package com.qf.shixi.controller;

import com.qf.shixi.entity.My;
import com.qf.shixi.result.ResponseCode;
import com.qf.shixi.result.ResponseData;
import com.qf.shixi.service.MyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * (My)表控制层
 *
 * @author makejava
 * @since 2021-10-27 17:42:02
 */
@RestController
@RequestMapping("my")
public class MyController {
    /**
     * 服务对象
     */
    @Resource
    private MyService myService;

    @ApiOperation(value = "微信登陆")
    @GetMapping("/space/login/{code}")
    public ResponseData wxLogin(@PathVariable String code) throws IOException {
        String token = MyService.wxLogin(code);
        if(token != null){
            return new ResponseData(token);
        }else{
            return new ResponseData(ResponseCode.ERROR);
        }
    }

    @ApiOperation(value = "修改用户信息,如果不存在,则直接添加")
    @PutMapping("/space/updata/info")
    public ResponseData updateWxUserInfo(@RequestBody My my){
        Boolean update = myService.update(my);
        if(update){
            return new ResponseData();
        }else{
            return new ResponseData(ResponseCode.ERROR);
        }

    }

    @ApiOperation(value = "修改用户电话号码,如果不存在,则直接添加")
    @PutMapping("/space/updata/tel")
    public ResponseData updateMytel(@RequestBody My my){
        Boolean updateTel = myService.update(my);
        if(updateTel){
            return new ResponseData();
        }else{
            return new ResponseData(ResponseCode.ERROR);
        }

    }

    @ApiOperation(value = "后台登陆")
    @PostMapping("/space/login")
    public ResponseData myLogin(@RequestBody My my){
        My my1 =  myService.myLogin(my);
        return new ResponseData(my1);

    }



}

